﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FactoryClassLibrary;//引入工厂类库
using ICameraClassLibrary;//引入相机接口类库

namespace _00_反射_相机_简单工厂模式
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //通过简单工厂模式-创建相机对象
            ICamera camera = CameraFactory.CreateInstance();
            //判断是否为空
            if (camera == null)
            {
                //提示加载失败
                MessageBox.Show("加载相机失败", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                return;
            }
            else
            {
                this.groupBox1.Text = "当前相机品牌:" + camera.BrandName;
                this.button1.Click += (s, e) => camera.OpenCamera();
                this.button2.Click += (s, e) => camera.SnapShot();
                this.button3.Click += (s, e) => camera.ContinuousShot();
                this.button4.Click += (s, e) => camera.CloseCamera();
            }
        }
    }
}
